import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../views/Login.vue'
import System from "../views/System";
import DefaultManual from "../components/system/DefaultManual";
//动态页面路由
/*import BookManage from "../components/system/BookManage";
import MagazineManage from "../components/system/MagazineManage";
import BorrowManage from "../components/system/BorrowManage";
import StaffManage from "../components/system/StaffManage";*/
//静态页面路由
import BookManage from "../components/system/static/BookManageStatic";
import MagazineManage from "../components/system/static/MagazineManageStatic";
import BorrowManage from "../components/system/static/BorrowManageStatic";
import StaffManage from "../components/system/static/StaffManageStatic";

import ProClaim from "../components/system/ProClaim";
import Editor from "../components/system/Editor"
import store from '../store/index'

Vue.use(VueRouter)


const routes = [
    {
        path: '/',
        name: 'login',
        component: Login
    },
    {
        path: '/system',
        name: 'system',
        component: System,
        meta: {requireAuth: true}, // 添加该字段，表示进入这个路由是需要登录的
        props: true,
        children: [
            {path: 'DefaultManual', name: 'DefaultManual', component: DefaultManual, meta: {requireAuth: true}},// 注意，子路由的开头位置，不要加 / 路径符
            {path: 'BookManage', component: BookManage, meta: {requireAuth: true}},
            {path: 'MagazineManage', component: MagazineManage, meta: {requireAuth: true}},
            {path: 'BorrowManage', component: BorrowManage, meta: {requireAuth: true}},
            {path: 'StaffManage', component: StaffManage, meta: {requireAuth: true}},
            {path: 'ProClaim', component: ProClaim, meta: {requireAuth: true}},
            {path: 'Editor', component: Editor, meta: {requireAuth: true}}
        ]
    },
    /*  {
        path: '/about',
        name: 'About',
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () => import(/!* webpackChunkName: "about" *!/ '../views/About.vue')
      }*/
]

const router = new VueRouter({
    mode: 'hash',
    base: process.env.BASE_URL,
    routes
})

router.beforeEach(((to, from, next) => {
    if (to.meta.requireAuth) {
        if (store.state.username) {
            next()
        } else {
            next({path: '/'})
        }
    } else {
        next()
    }
}))

export default router
